package com.xmg.boot.demo.bootlesson1.user.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.xmg.boot.demo.bootlesson1.user.annotation.StartSwaggerScan;
import com.xmg.boot.demo.bootlesson1.user.entity.Result;
import com.xmg.boot.demo.bootlesson1.user.entity.ResultUtil;
import com.xmg.boot.demo.bootlesson1.user.entity.dm.Department;
import com.xmg.boot.demo.bootlesson1.user.entity.dto.StudentDto;
import com.xmg.boot.demo.bootlesson1.user.service.dm.DepartmentService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author: ma
 * @date: 2023-11-30
 * @since: TODO
 */

@StartSwaggerScan
@RestController
public class DmController {

    @Autowired
    private DepartmentService departmentService;

    @ApiOperation(value="DM无条件分页",notes="无条件")
    @GetMapping("/getpage/{pageNum}/{pageSize}")
    public Result<List<Department>> getDmPage(@PathVariable("pageNum") Long pageNum
            , @PathVariable("pageSize") Long pageSize){
        //IPage<Department> page=new Page(pageNum,pageSize);
        IPage<Department> result = departmentService.findDepartmentPage(new Page(pageNum,pageSize));
        return ResultUtil.success(result);
    }


    @ApiOperation(value="测试事务",notes="无条件")
    @GetMapping("/getTrational")
    public Result<Boolean> getTrational(){
        departmentService.AddTwoTable();
        return ResultUtil.success(true);
    }

    @ApiOperation(value="存储过程",notes="无条件")
    @GetMapping("/getProc")
    public Result getProc(){
//        Map<String,Object> map=new HashMap<>();
//        map.put("department_id",2);
        List<Department> lst=departmentService.selectProc(2);

       // ObjectMapper objectMapper=new ObjectMapper();
        //String lst1=objectMapper.writeValueAsString(lst.get(0));
        //String lst2=objectMapper.writeValueAsString(lst.get(1));
        return ResultUtil.success(lst);
    }
}
